/**
  ******************************************************************************
  * File Name          : ToNetPub.c
  * Description        : This file provides code for the configuration
  *                      of the edp app instances.
  ******************************************************************************
  * @attention
  ******************************************************************************
  */
#include <string.h>
#include "bsp.h"
#include "tskcfg.h"
#include "cJSON.h"
#include "network.h"
#include "route.h"

void Network_PbulishMsg(Route_PayloadType *rtpl)
{
	MQTTPublishInfo_t pinfo;
	uint16_t packetId;
  uint8_t err;
  
  if((rtpl->trans_dir != ROUTE_TRSDIR_LOCAL_TO_NET) && \
     (rtpl->trans_dir != ROUTE_TRSDIR_SUBDEV_TO_NET) && \
     (rtpl->trans_dir != ROUTE_TRSDIR_LOCAL_CONFIG))
  {
    return;
  }
  
  switch(rtpl->dev_type)
  {
		case RT_DV_GW:
      err = Route_gw_up(rtpl);
			break;
		
    case RT_DV_HK:
      err = Route_ec_up(rtpl);
      break;
    
    case RT_DV_DK:
      err = Route_dk_up(rtpl);
      break;
    	
    case RT_DV_LX:
			err = Route_lx_up(rtpl);
			break;
    
		case RT_DV_CF:
      err = Route_cf_up(rtpl);
      break;
    
    case RT_DV_XC:
      err = Route_xc_up(rtpl);
      break;
    
    case RT_DV_GWCFG:
      Route_gwcfg(rtpl);
      return;
    
		/* 以下为不支持设备类型,如需支持,完成相应的处理函数,并在此调用 */
    default:
      err = 1;
      return;
  }
  
  if(err != 0)
  {
    return;
  }
  
  packetId = MQTT_GetPacketId( &MQTT_Context );
	
	pinfo.dup = false;
	pinfo.qos = MQTTQoS0;
	pinfo.retain = false;
	pinfo.pPayload = Network_Pub_payload;
	pinfo.payloadLength = strlen(Network_Pub_payload);
  
	pinfo.pTopicName = Network_Pub_topic;
  pinfo.topicNameLength = strlen(Network_Pub_topic);
  
	MQTT_Publish(&MQTT_Context, &pinfo, packetId);
  
  SysDbg_net_tx_tp("ntxt:%s\r\n", Network_Pub_topic);
  SysDbg_net_tx_pl("ntxp:%s\r\n", Network_Pub_payload);
}

